<template>
	<view class="min-vh-100  flex-col  w-100" style="background-color: #F3F3F3;">
		<view class="brs-12 mt-12  hh position-relative">
			<view class="d-flex flex-column px-3 reserva">
				<view class="card h-100  pt-12 " v-for="(v,i) in card_list" :key="i" @click="chooseCard(v,i)">
					<view class="bg-theme overflow-hidden brs-12 p-0 container">
						<view class="d-flex justify-content-between align-items-center card-top px-3 py-2  "
							:class="idx==i?'text-white bg-theme':''">
							<view class="font-600 ellipsis-line w-0 flex-1 ">
								{{v.name}}
							</view>
						</view>
						<view class="bg-white  d-flex  w-100 content" :class="idx==i?'sele-b bg-theme':'sele-a'">
							<view class=" w-100 " :class="idx==i?'select-color':''">
								<view class="d-flex justify-content-between flex-1  ">
									<view class="pic d-flex flex-column  align-items-center pe-2 "
										:class="idx==i?'pss':''">
										<view class="d-flex align-items-baseline">
											<view class="text-theme font-600 font-28">
												{{v.total_hour}}
											</view>
											<view class="font-12 text-666D73">
												小时
											</view>
										</view>
										<view class="font-14 font-600 text-666D73">
											总时长
										</view>
									</view>
									<view class="d-flex justify-content-between flex-1 align-items-center">
										<view class="detail ps-12 flex-1">
											<view
												class="d-flex font-14 font-500 text-AAB5BF align-items-center pb-1 flex-1">
												<view class="">
													适用门店：
												</view>
												<view class="font-14 font-600 text-222426 flex-1 ">
													{{v.store_name}}
												</view>
											</view>
											<view class="d-flex font-14 font-500 text-AAB5BF align-items-center pb-1">
												<view class="">
													适用教室：
												</view>
												<view class="font-14 font-600 text-222426 flex-1"
													@click="showRoom(v.rooms_list)">
													{{v.room_name}}
												</view>
											</view>
											<view class="d-flex font-14 font-500 text-AAB5BF align-items-center pb-1">
												<view class="">
													剩余时长：
												</view>
												<view class="font-14 font-600 text-222426">
													{{v.total_hour-v.hasconsumedhour}}小时
												</view>
											</view>
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view v-if="!card_list.length" style="margin-top: 400rpx;"
					class="empty d-flex justify-content-center flex-column align-items-center pt-5">
					<image src="../../static/imgs/emptyN.png" class="img" style="width: 288rpx;height:304rpx ;" />
					<view class=" font-16 font-500 " style="color: #303133;">暂无满足条件的卡券</view>
				</view>
			</view>

		</view>
		<u-popup v-model="show" mode="bottom" border-radius="16">
			<view  class="room_list">
				<view style="padding-bottom: 8rpx;" v-for="item,index in room_list" :key="index">
					{{item}}
				</view>
			</view>
		</u-popup>
		<view class="position-fixd save-action ">
			<view class="px-3">
				<button class="button font-20 bg-theme" v-if="card_list.length" :disabled="idx==-1"
					@click="cardPay">选择此卡支付</button>
				<button class="button font-20 bg-theme" v-else @click="cardPays">返回</button>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				card_list: [],
				idx: -1,
				selected_card_id: '',
				selected_card_name: '',
				show: false,
				room_list: []
			};
		},
		onLoad() {
			this.$u.api.getVoucherPayPageInfo(this.vuex_reserve_info)
				.then((res) => {
					if (1 == res.code) {
						this.card_list = res.data
						if (res.data.length) {
							this.selected_card_id = res.data[0].id
							this.selected_card_name = res.data[0].name
							this.idx = 0
						}
					}
				})
		},
		methods: {
			showRoom(list) {
				this.room_list = list || []
				this.show = true
			},
			chooseCard({
				id,
				name
			}, i) {
				this.idx = i
				this.selected_card_id = id
				this.selected_card_name = name
			},
			getInfo() {
				if (this.vuex_has_login) {
					this.$u.api.getUserInfo().then(res => {
						this.$u.vuex('vuex_user', {
							...this.vuex_user,
							...res.data
						})
					})
				}
			},
			cardPays() {
				uni.navigateBack()
			},
			cardPay() {
				uni.$emit('card', {
					card_id: this.selected_card_id,
					card_name: this.selected_card_name
				})
				uni.navigateBack()
				return
				uni.showModal({
					title: '提示',
					content: `你确认使用此卡进行扣次支付吗？`,
					success: (res) => {
						if (res.confirm) {
							this.$u.api.cardPay({
								reserve_id: this.vuex_reserve_info.reserve_id,
								room_id: this.vuex_reserve_info.room_id,
								selectdate: this.vuex_reserve_info.selectdate,
								timepills: this.vuex_reserve_info.timepills,
								card_id: this.selected_card_id
							}).then(res => {
								if (1 == res.code) {
									this.$u.toast('你的预约成功', 3000)
									this.getInfo()
									setTimeout(() => {
										this.$u.route({
											url: '/pages/myReservation/myReservation',
											type: 'tab',
										})
									}, 3000)
								} else {
									this.$u.toast(res.msg)
								}
							}, err => {
								this.$u.toast('如果预约失败，请联系管理员')
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
		},
	};
</script>

<style scoped lang="scss">
	.reserva {
		>view:last-child {
			padding-bottom: 40rpx;
		}
	}

	.card {
		&-top {
			background-color: #F692B6;
		}

		.container {
			box-shadow: 0rpx 0rpx 24rpx 0rpx rgba(39, 44, 103, 0.2);
		}

		.sele-a {
			padding: 48rpx 32rpx 54rpx;
		}

		.sele-b {
			padding: 0 8rpx 8rpx;
		}

		.content {
			.pic {
				border-right: 2rpx solid #E4E9ED;
			}

			.pss {
				padding-left: 24rpx;
			}
		}

		.select-color {
			background: linear-gradient(-45deg, transparent 40rpx, #F2F6FC 0);
			border-radius: 0 0 0 24rpx;
			padding-top: 48rpx;
			padding-bottom: 46rpx;

		}

	}

	.save-action {
		left: 50%;
		transform: translateX(-50%);
		bottom: 128rpx;
		width: 100%;

		.button {
			padding: 0 16px;
			height: 96rpx;
			line-height: 96rpx;
			color: rgb(255, 255, 255);
			font-weight: 600;
			border-radius: 40rpx 0 40rpx 40rpx;

			&[disabled]:not([type]) {
				background-color: #AAB5BF !important;
			}
		}
	}
	.room_list{
		padding: 40rpx 30rpx 60rpx;
		font-size: 28rpx;
	}
</style>